import { Application } from 'egg';
import {
  indexRule,
  createRule,
  baseRule,
  updateRule,
} from '../validate/wx/address';

/**
 * 小程序路由
 */
export default (app: Application) => {
  const { jwt } = app;

  return {
    'address.list': {
      method: 'GET',
      path: '/xxm/address/list',
      options: {
        tags: [ 'address/list' ],
        description: '收货地址列表',
        handler: app.controller.wx.address.list,
        middlewares: [jwt],
        validate: indexRule,
      },
    },
    'address.detail': {
      method: 'GET',
      path: '/xxm/address/:id',
      options: {
        tags: [ 'address/detail' ],
        description: '收货地址详情',
        handler: app.controller.wx.address.detail,
        middlewares: [ jwt ],
        validate: baseRule,
      },
    },
    'address.create': {
      method: 'POST',
      path: '/xxm/wx/address',
      options: {
        tags: [ 'address/create' ],
        description: '新增收货地址',
        handler: app.controller.wx.address.create,
        middlewares: [jwt],
        validate: createRule,
      },
    },
    'address.update': {
      method: 'PUT',
      path: '/xxm/address',
      options: {
        tags: [ 'address/update' ],
        description: '更新收货地址',
        handler: app.controller.wx.address.update,
        middlewares: [jwt],
        validate: updateRule,
      },
    },
    'address.destroy': {
      method: 'DELETE',
      path: '/xxm/address/:id',
      options: {
        tags: [ 'wx/address' ],
        description: '删除收货地址',
        handler: app.controller.wx.address.destroy,
        middlewares: [jwt],
        validate: baseRule,
      },
    },
  };
};
